/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sadhar.sipp.jenisbarang;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.sadhar.errhandler.ClassAntiNull;
import org.sadhar.sia.common.ClassConnection;

/**
 *
 * @author hendro
 */
public class JenisBarangDAOImpl implements JenisBarangDAO{

    public List<JenisBarang> list(int kodeKlasifikasi, String keySearch) throws Exception {
        List<JenisBarang> list = new ArrayList<JenisBarang>();
        String sql = "SELECT idJenisBarang,jenisBarang,kodeKlasifikasi,kodeJenisBarang FROM kamus.jenisBarang WHERE " +
                "kodeKlasifikasi=? AND jenisBarang LIKE ?";
        List<Map> rows = ClassConnection.getJdbc().queryForList(sql, new Object[]{
            kodeKlasifikasi,
            "%"+keySearch+"%"
        });
        for(Map m : rows){
            JenisBarang brg = new JenisBarang();
            brg.setIdJenisBarang(ClassAntiNull.AntiNullInt(m.get("idJenisBarang")));
            brg.setJenisBarang(ClassAntiNull.AntiNullString(m.get("jenisBarang")));
            brg.setKodeKlasifikasi(ClassAntiNull.AntiNullInt(m.get("kodeKlasifikasi")));
            brg.setKodeJenisBarang(ClassAntiNull.AntiNullString(m.get("kodeJenisBarang")));
            list.add(brg);
        }
        return list;
    }

}
